<template>
	<view class="ys">

		<view class="newslist">
			<view class="newsitem" v-for="(item,index) in newslist" :key="index"
				@click="toDetail('./detail?id='+item.id)">
				<view class="left">
					<view class="title">
						{{item.title}}
					</view>
					<view class="content">
						{{item.description}}
					</view>
					<view class="time">
						时间：{{item.create_time}}
					</view>
				</view>
			</view>
		</view>
		<view class="no-list">
			- 暂无数据 -
		</view>
	</view>
</template>

<script>
	import {
		news
	} from "@/api/api.js"
	export default {
		data() {
			return {
				newslist: [],
				page: 1,
				last_page: 1,
				tips: '暂无数据'
			}
		},
		onLoad() {
			this.notice()
		},
		onReachBottom() {
			if (this.page < this.last_page) {
				this.page++
				this.notice()
			}
		},
		methods: {
			notice() {
				news({
					page: this.page
				}).then(res => {
					let arr = res.data.data
					this.newslist = this.newslist.concat(arr)
					this.last_page = res.data.last_page
				})
			},
			toDetail(url) {
				uni.navigateTo({
					url
				})
			}
		}
	}
</script>

<style lang="scss">
	.ys {
		margin: auto;
		padding-top: 10px;
		min-height: calc(100vh - 44px);
		/* #ifdef H5 */
		min-height: calc(100vh - 44px);
		/* #endif */
		height: 100%;
		background: #f2f2f2;
		padding-bottom: 1px;

		.news-tab {
			display: flex;
			align-items: center;
			justify-content: space-between;

			.left {
				display: flex;
				align-items: center;
				width: 100%;
				justify-content: center;
				text-align: center;

				.item {
					margin-right: 20px;
					color: #222;
					font-size: 14px;
					position: relative;
					z-index: 1;
					flex: 1;
				}

				.active {
					font-size: 14px;
					font-weight: bold;
					color: #008FFF;
				}

				.active::after {
					position: absolute;
					content: '';
					bottom: -8px;
					width: 30px;
					left: 50%;
					transform: translate(-50%);
					height: 5px;
					background: #008FFF;
					z-index: 0;
				}
			}
		}

		.newslist {
			width: 96%;
			margin: 0 auto;
			border-radius: 10px;
			padding: 10px 0;

			.newsitem {
				display: flex;
				align-items: center;
				padding: 15px;
				box-sizing: border-box;
				background: #fff;
				margin-bottom: 8px;
				border-radius: 5px;

				.left {
					width: 100%;
					padding-right: 25upx;
					box-sizing: border-box;

					.title {
						font-size: 15px;
						color: #333;
						white-space: nowrap;
						text-overflow: ellipsis;
						overflow: hidden;
					}

					.content {
						font-size: 13px;
						color: #ababab;
						margin: 5px 0;
						display: -webkit-box;
						-webkit-line-clamp: 2;
						-webkit-box-orient: vertical;
						overflow: hidden;
					}

					.time {
						font-size: 13px;
						color: #bdbdbd;
						text-align: right;
					}
				}

				.right {
					width: 30%;
					height: 80px;
					display: flex;
					justify-content: center;
					align-items: center;
					overflow: hidden;
					border-radius: 5px;

					image {
						height: 80px;
					}
				}
			}

			.newsitem:last-child {
				border-bottom: 0;
			}
		}
	}
</style>